<template>
  <el-dialog title="分红权" :visible.sync="dialogVisible" width="48%" :before-close="handleClose">
    <div class="Recharge">
      <el-form ref="Recharge" :model="Recharge" :rules="rules" label-width="80px">
        <el-form-item label="分红权" prop="amount">
          <el-input type="number" v-model="Recharge.amount" placeholder="请输入分红权,减权请输入负数"></el-input>
        </el-form-item>

        <el-form-item label="会员等级" prop="paymentPluginId" class="paymentPluginId">
          <el-select v-model="vipId" clearable placeholder="会员等级">
            <el-option
              v-for="item in vipList"
              :key="item.id"
              :label="item.name"
              :value="item.vip"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item style="padding-top: 20px">
          <el-button type="primary" @click="Rechargeselect('Recharge')">确 定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog></template>
<script>
import {list as memberList1, list as memberList} from '@/api/member'
import { addStockRight } from "@/api/member";
import {list as vipList} from "@/api/vip";


export default {
  name: "Recharge.vue",
  props:['memberId'],
  data(){
    return {
      vipList:[],
      vipId:'',

      Account:'',
      memberName:'',
      membername:'',
      rules: {
        amount: [
          { required: true, message: '请输入分红权,减权请输入负数', trigger: 'blur' },
        ],
        agio: [
          { required: true, message: '请输入充值折扣', trigger: 'blur' },
        ],
        memo: [
          { required: true, message: '请输入充值备注', trigger: 'blur' },
        ],
      },
      dialogVisible:false,
      Recharge:{
        amount:"",
        agio:"",
        memo:""
      },
      memberList:[],
      cardType:'',
      paymentPluginId:''
    }
  },
  created() {
    this.loadMember(''),
      this.loadVip();
  },
  methods:{
    loadVip(){
      let params = new URLSearchParams();
      params.append('pageSize', 2000);
      vipList(params).then(response =>{
        response.data.data.forEach(item=>{
          if(item.vip == 0){
            item.name = "市场分红"
          }else if(item.vip == 1){
            item.name = "vip1"
          }else if(item.vip == 2){
            item.name = "vip2"
          }else if(item.vip == 3){
            item.name = "vip3"
          }else if(item.vip == 4){
            item.name = "vip4"
          }else if(item.vip == 5){
            item.name = "vip5"
          }
        })
        this.vipList=response.data.data

      })
    },
    Rechargeclick(rechargeType,memberId) {
      this.dialogVisible=true
      if(rechargeType == 'memberShipCard'){
        this.paymentPluginId = "cashPayPlugin"
        this.cardType = '0'
      }
      if(rechargeType == 'groupPurchaseCoupon'){
        this.paymentPluginId = "cashPayPlugin"
        this.cardType = '2'
      }
      if(rechargeType == 'welfareRecharge'){
        this.paymentPluginId = "cashPayPlugin"
        this.cardType = '3'
      }
      if(rechargeType == 'welfare4Recharge'){
        this.paymentPluginId = "cashPayPlugin"
        this.cardType = '4'
      }
      if(rechargeType == 'welfare5Recharge'){
        this.paymentPluginId = "cashPayPlugin"
        this.cardType = '5'
      }
      if(rechargeType == 'welfare6Recharge'){
        this.paymentPluginId = "cashPayPlugin"
        this.cardType = '6'
      }
      this.Recharge.amount=''
      this.Recharge.agio=''
      this.Recharge.memo=''
      this.memberName=''
    },
    remoteMethod(query) {
      this.loadMember(query)
    },
    selectMember(data) {
      this.memberId = data.id;
    },
    handleClose(){
      this.dialogVisible=false
    },
    Rechargeselect(){
      console.log(this.$refs.Recharge)
      this.$refs.Recharge.validate((valid) => {
        if (valid) {
          let params = {
            stockRight: this.Recharge.amount,
            memberId:this.memberId,
            type:this.vipId
          }
          addStockRight(params).then(res=>{
            this.dialogVisible=false
            this.$message("设置成功")
            this.$emit('loadOrder', )
          })
        }
      });
    },
    async  loadMember(query) {
      var _this = this
      let params = new URLSearchParams();
      params.append('keyword', query)
      await memberList1(params).then(response => {
        _this.memberList = response.data.data
        if(_this.memberList.length==0){
          this.memberphonetype=true
        }else{
          this.memberphonetype=false
        }
        if (_this.memberList.length > 4) {
          this.optionHeight = 'height:35px'
        } else {
          this.optionHeight = 'height:55px'
        }
      })
    },
  },
}
</script>

<style scoped>
.Recharge .el-form-item {
  margin-bottom: 20px!important;
}

/deep/ .el-dialog__body {
  margin-top: 20px !important;
}
.paymentPluginId >>> .el-select--medium{
  width: 100%;
}

</style>
